import { createCrudApi } from '@/utils/apiFactory';
import request from '@/utils/unirequest';
import type { IResult } from '@/type/common';
import type {
  ISysDailySubstitutionRequestBill,
  ISysDailySubstitutionRequestBillView,
  ISysDailySubstitutionRequestBillVm,
  ISysPersonSearchQuery,
  ISysPersonSearchResponse
} from './interface';

export default function SysDailySubstitutionRequestBillApi() {
  // 基础CRUD用工厂生成
  const baseCrud = createCrudApi<
    ISysDailySubstitutionRequestBillView,
    ISysDailySubstitutionRequestBillVm,
    ISysDailySubstitutionRequestBill
  >('/api/SysDailySubstitutionRequestBill');

  return {
    ...baseCrud,
    // 额外的特殊接口
    // 获取单据编号接口
    async getBillCode(): Promise<IResult<string>> {
      return await request.get('/api/SysDailySubstitutionRequestBill/PredictCode');
    },
    // 审核接口
    async approve(data: ISysDailySubstitutionRequestBillVm): Promise<ISysDailySubstitutionRequestBill> {
      return await request.post('/api/SysDailySubstitutionRequestBill/approve?tag=', data);
    },
    // 员工搜索接口
    async searchPersons(query: ISysPersonSearchQuery): Promise<ISysPersonSearchResponse> {
      return await request.post('/api/SysPerson/Search', query);
    }
  };
}

